from ultralytics import YOLO
import cv2

# 加载模型
model = YOLO('yolov8n.pt')

# 输入视频路径（可替换为动漫视频）
video_path = 'test.mp4'
cap = cv2.VideoCapture(video_path)

# 循环读取视频帧
while cap.isOpened():
    ret, frame = cap.read()
    if not ret:
        break  # 视频结束

    # 检测当前帧
    results = model(frame)

    # 标注帧并显示
    annotated_frame = results[0].plot()
    cv2.imshow('Anime Detection', annotated_frame)

    # 按q退出
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()